//
//  ActiveTableViewCell.m
//  豆瓣masonry
//
//  Created by dllo on 15/12/14.
//  Copyright © 2015年 SMH. All rights reserved.
//

#import "ActiveTableViewCell.h"
#import "Masonry.h"

@implementation ActiveTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.blueBackgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_eventlistcell"]];
        [self.contentView addSubview:self.blueBackgroundImageView];
        
        self.whiteBackgroungImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_share_large@2x"]];
        [self.blueBackgroundImageView addSubview:self.whiteBackgroungImageView];
        

        self.labelTitle = [[UILabel alloc] init];
        self.labelTitle.font = [UIFont systemFontOfSize:18];
        [self.blueBackgroundImageView addSubview:self.labelTitle];

        self.imageWithTime = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_date@2x"]];
        [self.whiteBackgroungImageView addSubview:self.imageWithTime];
        
        self.labelTime = [[UILabel alloc] init];
        //        self.labelTime.backgroundColor = [UIColor lightGrayColor];
        self.labelTime.font = [UIFont systemFontOfSize:15];
        [self.whiteBackgroungImageView addSubview:self.labelTime];
        

        self.imagewithAddress = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_spot@2x"]];
        [self.whiteBackgroungImageView addSubview:self.imagewithAddress];
        
        self.labelAddress = [[UILabel alloc] init];
        //        self.labelAddress.backgroundColor = [UIColor orangeColor];
        self.labelAddress.font = [UIFont systemFontOfSize:15];
        [self.whiteBackgroungImageView addSubview:self.labelAddress];
        //

        self.imageWithType = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_catalog@2x"]];
        [self.whiteBackgroungImageView addSubview:self.imageWithType];
        
        self.labelType = [[UILabel alloc] init];
        //        self.labelType.backgroundColor = [UIColor redColor];
        self.labelType.font = [UIFont systemFontOfSize:15];
        [self.whiteBackgroungImageView addSubview:self.labelType];
        

        self.labelWisher_count = [[UILabel alloc] init];
        //        self.labelWisher_count.backgroundColor = [UIColor lightGrayColor];
        self.labelWisher_count.font = [UIFont systemFontOfSize:15];
        [self.whiteBackgroungImageView addSubview:self.labelWisher_count];



        self.labelParticipant_count = [[UILabel alloc] init];
        self.labelParticipant_count.font = [UIFont systemFontOfSize:15];
        //        self.labelParticipant_count.backgroundColor = [UIColor lightGrayColor];
        [self.whiteBackgroungImageView addSubview:self.labelParticipant_count];
  

        self.imageViewPhoto = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1f21352e2418d18f781920d1c01667f1.jpg"]];
        self.imageViewPhoto.backgroundColor = [UIColor lightGrayColor];
        [self.whiteBackgroungImageView addSubview:self.imageViewPhoto];


        
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    

    [self.blueBackgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.right.mas_equalTo(-5);
        make.top.mas_equalTo(10);
        make.bottom.mas_equalTo(-10);
        
    }];
    

    [self.whiteBackgroungImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5);
        make.top.mas_equalTo(self.blueBackgroundImageView.frame.size.height/ 5);
        make.bottom.mas_equalTo(-10);
        make.right.mas_equalTo(-5);
        
    }];
    

    [self.labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(0);
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(self.whiteBackgroungImageView.mas_top).offset(0);
    }];
    
    
    

    [self.imageWithTime mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(8);
        make.height.width.mas_equalTo(20);
    }];
    

    //    self.labelTime.backgroundColor = [UIColor redColor];
    [self.labelTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(self.imageWithTime.mas_right).offset(10);
        make.right.mas_equalTo(self.imageViewPhoto.mas_left).offset(- 10);
        //        make.bottom.mas_equalTo(- self.whiteBackgroungImageView.frame.size.height / 5 * 4);
        make.bottom.mas_equalTo(self.labelAddress.mas_top).offset(-5);
    }];
    
    

    [self.imagewithAddress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(self.imageWithTime.mas_bottom).with.offset(3);
        make.width.height.mas_equalTo(20);
    }];
    

    [self.labelAddress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imagewithAddress.mas_right).offset(10);
        make.top.mas_equalTo(self.labelTime.mas_bottom).with.offset(5);
        make.right.mas_equalTo(self.imageViewPhoto.mas_left).offset(-10);
        make.bottom.mas_equalTo(self.labelType.mas_top).offset(-5);
        
    }];
    //
    
    
    [self.imageWithType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(self.imagewithAddress.mas_bottom).offset(3);
        make.width.height.mas_equalTo(20);
    }];
    

    [self.labelType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imageWithType.mas_right).with.offset(10);
        make.top.mas_equalTo(self.labelAddress.mas_bottom).with.offset(5);
        make.right.mas_equalTo(self.imageViewPhoto.mas_left).with.offset(-10);
        
        
    }];
    //    self.labelWisher_count.frame = CGRectMake(20, height / 5 * 4 - 10, width / 4 + 20, height / 5);
    

    [self.labelWisher_count mas_makeConstraints:^(MASConstraintMaker *make) {
        //
        make.left.mas_equalTo(20);
        make.top.mas_equalTo(self.labelType.mas_bottom).with.offset(10);
        //        make.right.mas_equalTo(self.labelParticipant_count.mas_left).offset(10);
        //        make.width.mas_equalTo(self.labelParticipant_count.frame.size.width);
    }];

    //    self.labelParticipant_count.backgroundColor = [UIColor redColor];
    //    self.labelWisher_count.backgroundColor = [UIColor blackColor];
    [self.labelParticipant_count mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.labelWisher_count.mas_right).with.offset(10);
        make.top.mas_equalTo(self.labelType.mas_bottom).with.offset(10);
        make.right.mas_equalTo(self.imageViewPhoto.mas_left).offset(-20);
        //        make.width.mas_equalTo(self.labelWisher_count.frame.size.width);
        
    }];
    
    
    //
    //    self.labelParticipant_count.frame = CGRectMake(60 + width / 4 - 20, height / 5 * 4 - 10, width / 4 + 20, height / 5);
    //
    //    self.imageViewPhoto.frame = CGRectMake(width / 5 * 4 - 17, 5, width / 4 - 10, height - 13);
    [self.imageViewPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.labelTime.mas_right).offset(10);
        make.top.mas_equalTo(8);
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(- 5);
        make.width.mas_equalTo(self.whiteBackgroungImageView.frame.size.width/ 4);
        
    }];

}

- (void)setModel:(Model *)model
{

    self.labelTitle.text = model.title;
    
    NSRange rang = {5, 11};
    NSString *strBegin = [model.begin_time substringWithRange:rang];
    NSString *strEnd = [model.end_time substringWithRange:rang];
    self.labelTime.text = [NSString stringWithFormat:@"%@ -- %@", strBegin, strEnd];
    
    self.labelAddress.text = model.address;
    self.labelType.text = model.category_name;
    self.labelWisher_count.text = [NSString stringWithFormat:@"感兴趣：%@", model.wisher_count];
    
    self.labelParticipant_count.text = [NSString stringWithFormat:@"参加：%@", model.participant_count];
    
    
    
    
    
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
